<template>
  <view
    class="bg-light flex flex-column"
    :style="'padding-bottom:' + fixedHeight + 'px'"
  >
    <!-- 选项 -->
    <view class="flex mx-3" v-if="SalesOrder.length == 1">
      <view
        @click="handlecount(0)"
        class="rounded-lg flex justify-center w-100 py-2"
        :class="count == 0 ? 'bg-info' : 'bg-white'"
        style="border-radius: 14rpx 0 0 0"
      >
        <text
          class="font font-weight-bold"
          :class="count == 0 ? 'text-white' : 'text-info'"
          >配送地址</text
        >
      </view>
      <view
        @click="handlecount(1)"
        class="flex justify-center w-100 py-2"
        :class="count == 1 ? 'bg-info' : 'bg-white'"
        style="border-radius: 0 14rpx 0 0"
      >
        <text class="font" :class="count == 1 ? 'text-white' : 'text-info'"
          >用户自提</text
        >
      </view>
    </view>
    <!-- 收货地址 -->
    <view v-if="count == 0" class="">
      <!--请选择收货地址  -->
      <view
        v-if="Address == null"
        @click="onAddress()"
        class="bg-white mx-3 mb-4 px-2 py-3 rounded-lg flex align-center"
        style="position: relative"
      >
        <text class="font-sm">请选择收货地址</text>
        <text class="font" style="position: absolute; right: 20rpx">&gt;</text>
      </view>
      <!-- 结果 -->
      <view v-else @click="onAddress()" class="bg-white mx-3 p-3 rounded-lg">
        <view class="flex align-center">
          <image
            :src="Domain_ICON + '/position.png'"
            class="rounded-circle bg-info"
            style="width: 30rpx; height: 30rpx"
            mode=""
          ></image>
          <text class="font ml-1">{{ Address.Name }}</text>
          <text class="font ml-1">{{ Address.Phone }}</text>
        </view>
        <view class="pl-4">
          <text class="font-sm">配送地址：{{ Address.Address }}</text>
        </view>
      </view>
    </view>
    <view v-if="count == 1" class="">
      <view @click="onAddress()" class="bg-white mx-3 p-3 rounded-lg">
        <view class="flex align-center">
          <image
            :src="Domain_ICON + '/position.png'"
            class="rounded-circle bg-info"
            style="width: 30rpx; height: 30rpx"
            mode=""
          ></image>
          <text class="font ml-1">{{ Address.Name }}</text>
          <text class="font ml-1">{{ Address.Phone }}</text>
        </view>
        <view class="pl-4">
          <text class="font-sm">配送地址：用户自提</text>
        </view>
      </view>
    </view>
    <!-- 支持选择多个收货地址 -->
    <view
      class="bg-white mx-3 mb-4 px-2 py-3 flex justify-between align-center font"
      @click="Select_multiple_harvest_addresses('bottom')"
      v-if="Quantity > 1"
      style="border-top: 1px solid #f5f5f5; border-radius: 0 0 14rpx 14rpx"
    >
      <view class="flex align-center justify-center">
        <image
          src="/static/icon/jia.png"
          mode="scaleToFill"
          style="width: 40rpx; height: 40rpx"
        />
        <view class="ml-2">支持选择多个收货地址</view>
      </view>
      <view @click="querData">去修改></view>
    </view>
    <!-- 商品信息 -->
    <view
      class="bg-white mx-4 mb-4 px-2 py-3 rounded-lg"
      v-for="(item, index) in SalesOrder"
      :key="index"
    >
      <!-- 商品信息 -->
      <view v-for="(item2, index2) in item.Data" :key="index2">
        <view
          class="flex align-center"
          style="padding: 20rpx"
          v-if="item2.Sales_Address"
        >
          <image
            :src="Domain_ICON + '/position.png'"
            class="rounded-circle bg-info"
            style="width: 30rpx; height: 30rpx"
            mode=""
          ></image>
          <text class="font ml-1">{{ item2.Sales_Address }}</text>
        </view>
        <view class="flex" style="position: relative">
          <image
            class="rounded-lg flex-shrink"
            style="width: 150rpx; height: 150rpx"
            :src="Domain_IMG + item2.Picture_URL"
            mode=""
          ></image>
          <view
            class="ml-2 pr-10 text-ellipsis"
            style="width: 100%; position: relative"
          >
            <text class="font">{{ item2.Article_Name }}</text
            ><br />
            <text class="font-sm text-muted"
              >规格:{{ item2.Specifications_Name }}</text
            >
            <text class="font-sm" style="position: absolute; bottom: 0; left: 0"
              >￥{{ Price(item2.Sales_Unit_Price) }}</text
            >
          </view>
          <text
            class="font-sm"
            style="
              position: absolute;
              right: 0;
              height: 100%;
              line-height: 150rpx;
            "
            >×{{ item2.quantity }}</text
          >
        </view>
        <view class="py-2">
          <text class="font-sm text-muted" style="display: inline-block"
            >产品注意事项</text
          >
          <text class="font-sm" style="display: inline-block; float: right"
            >严格品质 退货无忧 &gt;</text
          >
        </view>
        <view class="bg-light p-3 rounded-lg flex align-center">
          <text class="font flex-shrink">订单留言：</text>
          <textarea
            v-model="item2.message"
            class="font"
            placeholder-class="text-muted"
            style="width: 100%"
            placeholder="请输入你的订单备注信息"
            auto-height
          ></textarea>
        </view>
      </view>
    </view>
    <!-- 商品金额 -->
    <view class="mx-4 rounded-lg p-3 bg-white">
      <text class="font text-muted">商品金额：</text>
      <text class="font" style="display: inline-block; float: right"
        >￥{{ Price(Amount) }}</text
      >
    </view>
    <!-- 配送金额 -->
    <view
      v-if="ispay && !count"
      class="mx-4 flex justify-between align-center mt-2 rounded-lg p-3 bg-white"
    >
      <view class="font text-muted"
        >配送金额：<text class="font-small"
          >(当商品金额到达￥{{ Sales_Amount }}时可免配送费)</text
        ></view
      >
      <text class="font" style="display: inline-block; float: right"
        >￥{{ Price(DeliveryAmount) }}</text
      >
    </view>
    <!-- 配送距离 -->
    <view v-if="ispay && !count" class="mx-4 mt-2 rounded-lg p-3 bg-white">
      <text class="font text-muted">当前地址配送距离约：</text>
      <text class="font" style="display: inline-block; float: right"
        >{{ distance }}km</text
      >
    </view>
    <!-- 底层总计 -->
    <view id="fixed" class="fixed-bottom py-1 bg-white" style="z-index: 99">
      <view class="m-auto flex align-center justify-between" style="width: 90%">
        <view class="" style="width: 100%">
          <text class="font">共{{ Quantity }}件 合计</text
          ><text class="font-md font-weight-bold"
            >￥{{ accAdd(Amount, count ? 0 : DeliveryAmount) }}</text
          >
        </view>
        <view
          @click="submit()"
          v-if="ispay || count"
          class="flex-shrink text-white bg-info py-3 text-center rounded-lg"
          hover-class="bg-hover-info"
          :hover-stay-time="150"
          style="width: 35%"
        >
          <text class="font">提交订单</text>
        </view>
        <view
          v-else
          class="flex-shrink text-white bg-danger py-3 text-center rounded-lg"
          hover-class="bg-hover-info"
          :hover-stay-time="150"
          style="width: 35%"
        >
          <text class="font-sm">该地区暂时无法配送</text>
        </view>
      </view>
    </view>
    <!--  -->
    <showPaynew
      :amount="accAdd(Amount, count ? 0 : DeliveryAmount)"
      :sales_order="sales_order"
      :Article_Name="Article_Name"
      :show="isShow"
      @Close="handleClose()"
    ></showPaynew>
    <!--  -->
    <showPaysnew
      :amount="accAdd(Amount, count ? 0 : DeliveryAmount)"
      :sales_orders="sales_orders"
      :Article_Name="Article_Name"
      :show="isShow2"
      @Close="handleClose()"
    ></showPaysnew>
    <!-- 用户协议 -->
    <view class="mask" v-if="mask">
      <view class="model_box">
        <view class="mb-tit">用户协议和隐私政策</view>
        <view class="mb-content">
          <view class="mb-con">尊敬的用户您好！</view>
          <view class="mb-con"
            >请您务必认真阅读、充分理解“用户服务协议”和“隐私政策”各条款，包括但不限于为了向您提供数据、分享、统计等服务所要获取的权限信息。</view
          >
          <view class="mb-con1">
            <navigator class="mb-a" url="/pages/my/privacyPolicy"
              >《用户服务协议》</navigator
            >
            和
            <navigator class="mb-a" url="/pages/my/privacyPolicy"
              >《隐私政策》</navigator
            >
          </view>
          <text
            >请您仔细阅读上方的的用户协议与隐私政策，请点击同意接受我们的服务</text
          >
        </view>
        <view class="checkbox">
          <view class="qr">
            <navigator class="noUse" target="miniProgram" open-type="exit"
              >暂不使用</navigator
            >
            <view class="agree" @click="agree">同意</view>
          </view>
        </view>
      </view>
    </view>
    <!-- 展开 -->
    <uni-popup ref="popup" background-color="#f5f5f5" class="p-2">
      <view class="font p-3 text-center">修改收货地址</view>
      <view
        class="bg-white rounded-lg w-100 mb-2"
        v-for="(item, index) in SalesOrder2"
        :key="index"
        style="box-sizing: border-box; padding: 20rpx; overflow: hidden"
      >
        <view v-if="SalesOrder2.length < 2">
          <view class="bg-white mx-3 mb-2 p-3 rounded-lg">
            <view class="flex align-center">
              <image
                :src="Domain_ICON + '/position.png'"
                class="rounded-circle bg-info"
                style="width: 30rpx; height: 30rpx"
                mode=""
              ></image>
              <text class="font ml-1">{{ Address.Name }}</text>
              <text class="font ml-1">{{ Address.Phone }}</text>
            </view>
            <view class="pl-4">
              <text class="font-sm">配送地址：{{ Address.Address }}</text>
            </view>
          </view>
        </view>
        <view v-else>
          <view class="bg-white mx-3 mb-2 p-3 rounded-lg">
            <view class="flex align-center">
              <image
                :src="Domain_ICON + '/position.png'"
                class="rounded-circle bg-info"
                style="width: 30rpx; height: 30rpx"
                mode=""
              ></image>
              <text class="font ml-1">{{ item.Address.Name }}</text>
              <text class="font ml-1">{{ item.Address.Phone }}</text>
            </view>
            <view class="pl-4">
              <text class="font-sm">配送地址：{{ item.Address.Address }}</text>
            </view>
          </view>
        </view>
        <view v-for="(item2, index2) in item.Data" :key="index2">
          <view
            class="flex align-center"
            style="padding: 20rpx"
            v-if="item.Sales_Address"
          >
            <image
              :src="Domain_ICON + '/position.png'"
              class="rounded-circle bg-info"
              style="width: 30rpx; height: 30rpx"
              mode=""
            ></image>
            <text class="font ml-1">{{ item2.Sales_Address }}</text>
          </view>
          <view class="flex" style="position: relative">
            <image
              class="rounded-lg flex-shrink"
              style="width: 150rpx; height: 150rpx"
              :src="Domain_IMG + item2.Picture_URL"
              mode=""
            ></image>
            <view
              class="ml-2 pr-10 text-ellipsis"
              style="width: 100%; position: relative"
            >
              <text class="font">{{ item2.Article_Name }}</text
              ><br />
              <text class="font-sm text-muted"
                >规格:{{ item2.Specifications_Name }}</text
              >
              <text
                class="font-sm"
                style="position: absolute; bottom: 0; left: 0"
                >￥{{ Price(item2.Sales_Unit_Price) }}</text
              >
            </view>
            <text
              class="font-sm"
              style="
                position: absolute;
                right: 0;
                height: 100%;
                line-height: 150rpx;
              "
              >{{ item2.quantity }}</text
            >
          </view>
          <view class="py-2">
            <text class="font-sm text-muted" style="display: inline-block"
              >产品注意事项</text
            >
            <text class="font-sm" style="display: inline-block; float: right"
              >严格品质 退货无忧 &gt;</text
            >
          </view>
          <view class="flex align-center justify-end">
            <view
              class="rounded-lg border font p-1 pl-2 pr-2"
              @click="MultipleAddresses(item2)"
              >修改地址</view
            >
          </view>
        </view>
      </view>
      <view
        @click="modify()"
        style="background-color: #17a2b8; width: 200rpx; margin: 10rpx auto"
        class="text-center font text-white p-2 rounded-lg"
        >确认修改
      </view>
    </uni-popup>
    <!-- 多个地址分配数量 -->
    <uni-popup ref="popupNumber" background-color="#f5f5f5" class="">
      <view class="font p-3 text-center">选择新的收货地址</view>
      <view class="bg-white rounded-lg w-100 mb-2">
        <view class="font p-3">原地址</view>
        <view class="bg-white mx-3 mb-2 p-3 rounded-lg">
          <view class="flex align-center">
            <image
              :src="Domain_ICON + '/position.png'"
              class="rounded-circle bg-info"
              style="width: 30rpx; height: 30rpx"
              mode=""
            ></image>
            <text class="font ml-1">{{ Address.Name }}</text>
            <text class="font ml-1">{{ Address.Phone }}</text>
          </view>
          <view class="pl-4">
            <text class="font-sm">配送地址：{{ Address.Address }}</text>
          </view>
        </view>
      </view>
      <view class="bg-white rounded-lg w-100 mb-2">
        <view
          class="uni-list-cell uni-list-cell-pd"
          v-for="(item, index) in addressList"
          :key="index"
        >
          <view class="flex align-center p-3">
            <checkbox
              :value="item.Address_SerialNumber"
              :checked="item.isSettle"
              @click="radioChange(index, item)"
            />
            <view class="font" style="flex: 1">
              <view> {{ item.Address }}{{ item.Address_Details }}</view>
              <view>{{ item.Name }}&nbsp;{{ item.Phone }}</view>
              <!-- <view class="flex" v-if="item.isSettle"> -->
              <!-- 先实现主体功能  -->
              <view class="flex">
                <view class="font-sm bg-light rounded-lg p-1" style="width: 80%"
                  >配送到该地址的数量</view
                >
                <view class="flex justify-center align-center rounded-circle">
                  <view
                    @click.stop="subGoods(index, item)"
                    class="font-md text-center text-white flex justify-center align-center"
                    style="
                      width: 50rpx;
                      height: 50rpx;
                      background-color: #17a2b8;
                    "
                    >-</view
                  >
                  <view
                    class="text-center font bg-white border"
                    style="
                      width: 50rpx;
                      height: 50rpx;
                      line-height: 50rpx;
                      padding: 0;
                      border-top: 1rpx solid #17a2b8;
                      border-bottom: 1rpx solid #17a2b8;
                      color: #17a2b8;
                      box-sizing: border-box;
                    "
                  >
                    {{ parseInt(item.Quantity) }}
                  </view>
                  <view
                    @click.stop="addGoods(index, item)"
                    class="font-md text-center text-white flex justify-center align-center"
                    style="
                      width: 50rpx;
                      height: 50rpx;
                      background-color: #17a2b8;
                    "
                    >+</view
                  >
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
      <view
        @click="modify()"
        style="background-color: #17a2b8; width: 200rpx; margin: 10rpx auto"
        class="text-center font text-white p-2 rounded-lg"
        >确认修改</view
      >
    </uni-popup>
  </view>
</template>

<script>
const app = getApp();
import showPaynew from "@/components/payment/paynew.vue";
import showPaysnew from "@/components/payment/paysnew.vue";
import { NowTime } from "@/static/js/DateUtil.js";
import { accMul, accAdd } from "@/static/js/GeneralUtil.js";
import { getAddressList } from "@/api/global.js";
import { submitODPquery, submitODPadd } from "@/api/update.js";
export default {
  components: {
    showPaynew,
    showPaysnew,
  },
  data() {
    return {
      count: 0, //自提或个人信息
      Domain_IMG: app.globalData.Domain_IMG, //全局变量--域名
      isShow: false, //调起支付方式
      isShow2: false, //调起支付方式
      ispay: true,
      payway: true, //选取支付方式
      fixedHeight: 0, //底部悬浮栏高度
      Address: null, //默认地址
      SalesOrder: [], //页面渲染用的数组
      SalesOrder2: [], //临时数组
      mask: false, //协议
      Amount: 0,
      DeliveryAmount: 0,
      Sales_Amount: 0,
      distance: 0,
      Quantity: 0,
      Article_Name: [],
      times: "",
      sales_orders: [],
      sales_order: {
        Sales_Order_SerialNumber: "",
        Store_SerialNumber: "",
        Sales_Date: this.times,
        Open_ID: app.globalData.openid,
        Sales_Amount: "",
        Sales_Contacts: "",
        Sales_Phone: "",
        Sales_Address: "",
        Sales_Message: "",
        Collection_Amount: 0,
        Delivery_Amount: 0,
        Sales_ID: "xiaoshou1",
        Receive_Type: 0,
        Refund_Type: 0,
        App_ID: app.globalData.appid,
        Enterprise_Info_SerialNumber: app.globalData.enterprise,
        Children: {
          sales_order_detail: [
            {
              Sales_Order_Detail_SerialNumber: "",
              Sales_Order_SerialNumber: "",
              Sales_Unit_Price_Stock_SerialNumber: "",
              Article_SerialNumber: "",
              Sign: "无货货主",
              Quantity: "",
              Unit_Price: "",
              Sales_Unit_Price: "",
              Amount: "",
              Receive_Type: 0,
              Refund_Type: 0,
              Enterprise_Info_SerialNumber: app.globalData.enterprise,
              Article_Specifications_SerialNumber: "",
            },
          ],
        },
      },
      Domain_ICON: app.globalData.Domain_ICON, //全局变量域名
      type: "", //弹出层类型
      Address_index: 0, //地址索引
      addressForm: {
        //地址form
        page: 1,
        limit: 10,
        App_ID: app.globalData.appid,
        Open_ID: app.globalData.openid,
      },
      addressList: [], //地址列表
      current: "", //默认地址
      num: 0, //分配数量
      AddressI: {}, //临时地址对象
      Address: {},
      dataII: [],
    };
  },
  onShow() {
    if (uni.getStorageSync("AddressData")) {
      //取出本地存储地址
      this.Address = uni.getStorageSync("AddressData");
      this.Getdistance(uni.getStorageSync("Store_SerialNumber"));
      if (this.count == 0) {
        this.sales_order.Sales_Address = this.Address.Address.replace(" ", "/")
          .replace(" ", "/")
          .replace(" ", "/");
      } else if (this.count == 1) {
        this.sales_order.Sales_Address = "用户自提";
      } else {
        //单独添加收货地址
        this.SalesOrder[this.Address_index].Sales_Address =
          this.Address.Address.replace(" ", "/");
      }
      this.sales_order.Sales_Contacts = this.Address.Name;
      this.sales_order.Sales_Phone = this.Address.Phone;
      if (this.payway) {
        this.sales_orders.forEach((item) => {
          (item.Sales_Address = this.Address.Address.replace(" ", "/")
            .replace(" ", "/")
            .replace(" ", "/")),
            (item.Sales_Contacts = this.Address.Name);
          item.Sales_Phone = this.Address.Phone;
        });
      }
    }
    if (uni.getStorageSync("mask")) {
      //本地存储地址
      this.mask = false;
    } else {
      this.mask = true;
    }
  },
  onLoad(options) {
    this.fixed();
    if (options.key == undefined) {
      this.payway = false;
      let larr_SalesOrder = JSON.parse(decodeURIComponent(options.SalesOrder));
      this.SalesOrder.push({
        Address: uni.getStorageSync("AddressData"),
        Data: larr_SalesOrder,
      });
      this.SalesOrder2 = this.SalesOrder;
      this.time();
      // this.larr_SalesOrder.Data.forEach((item) => {
      //   this.Article_Name.push(item.Article_Name);
      //   item.message = "";
      //   this.sales_order.Sales_Date = this.times;
      //   this.sales_order.Children.sales_order_detail[0].Amount =
      //     this.sales_order.Children.sales_order_detail[0].Amount +
      //     accMul(item.Sales_Unit_Price, item.quantity);
      //   this.sales_order.Children.sales_order_detail[0].Quantity =
      //     this.sales_order.Children.sales_order_detail[0].Quantity +
      //     parseInt(item.quantity);
      //   this.sales_order.Store_SerialNumber = item.Store_SerialNumber;
      //   this.sales_order.Sales_Amount = accMul(
      //     item.Sales_Unit_Price,
      //     item.quantity
      //   );
      //   this.Amount = this.sales_order.Children.sales_order_detail[0].Amount;
      //   this.Quantity =
      //     this.sales_order.Children.sales_order_detail[0].Quantity;
      //   this.sales_order.Children.sales_order_detail[0] = {
      //     Sales_Order_Detail_SerialNumber: "",
      //     Sales_Order_SerialNumber: "",
      //     Sales_Unit_Price_Stock_SerialNumber:
      //       item.Sales_Unit_Price_Stock_SerialNumber,
      //     Article_SerialNumber: item.Article_SerialNumber,
      //     Quantity: parseInt(item.quantity),
      //     Unit_Price: item.Unit_Price,
      //     Sales_Unit_Price: item.Sales_Unit_Price,
      //     Amount: accMul(item.Sales_Unit_Price, item.quantity),
      //     Receive_Type: 0,
      //     Refund_Type: 0,
      //     Enterprise_Info_SerialNumber: app.globalData.enterprise,
      //     Article_Specifications_SerialNumber:
      //       item.Article_Specifications_SerialNumber,
      //   };
      // });
      this.Amount =
        larr_SalesOrder[0].Sales_Unit_Price * larr_SalesOrder[0].quantity;
      this.Quantity = larr_SalesOrder[0].quantity;
    } else {
      this.payway = true;
      this.SalesOrder = JSON.parse(decodeURIComponent(options.SalesOrder));
      this.time();
      this.SalesOrder.forEach((item) => {
        this.Article_Name.push(item.Article_Name);
        item.message = "";
        item.quantity = item.Quantity;
        this.Amount = accAdd(this.Amount, item.Amount);
        this.Quantity = this.Quantity + parseInt(item.Quantity);
        this.sales_order.Store_SerialNumber = item.Store_SerialNumber;
        this.sales_order.Sales_Amount = accMul(
          item.Sales_Unit_Price,
          item.quantity
        );
        this.sales_orders.push({
          Sales_Order_SerialNumber: item.Sales_Order_SerialNumber,
          Sales_Date: this.times,
          Sales_Unit_Price: item.Sales_Unit_Price,
          Store_SerialNumber: item.Store_SerialNumber,
          Amount: item.Amount,
          Quantity: item.Quantity,
          Sales_Unit_Price_Stock_SerialNumber:
            item.Sales_Unit_Price_Stock_SerialNumber,
        });
      });
    }
    this.addressListMethods();
  },
  watch: {},
  created() {},
  computed: {
    Price() {
      //补零
      return function (price) {
        if (price) {
          if (RegExp(/\./).exec(price)) {
            return price;
          } else {
            return price + ".00";
          }
        } else {
          return "";
        }
      };
    },
  },
  methods: {
    // 确认修改 按钮
    async modify() {
      //整理数组
      this.addressList.forEach((item) => {
        const deepCopyOfDataII = JSON.parse(JSON.stringify(this.dataII)); // 产品相关数据
        if (item.isSettle && item.Quantity > 0) {
          deepCopyOfDataII.quantity = item.Quantity;
          this.SalesOrder2.push({
            Address: item,
            Data: [deepCopyOfDataII],
          });
        }
      });
      const obj = {};
      obj.Key = "B_classify_test1";
      obj.Main = JSON.stringify(this.SalesOrder2);
      obj.Expire = "7200";
      this.addressListMethods(); // 确认修改多个地址后 初始化地址列表信息
      await submitODPadd(obj);
      this.Getdistance(uni.getStorageSync("Store_SerialNumber"));
      this.$refs.popupNumber.close();
      this.$refs.popup.close();
    },
    // 配送地址的数量 减少
    subGoods(index, item) {
      //减少
      if (this.addressList[index].Quantity == 0) {
        uni.showToast({
          title: "商品数量已达下限",
          icon: "error",
        });
      } else {
        // 原数据判断
        // this.addressList[index].Quantity = this.addressList[index].Quantity - 1;
        item.Quantity = item.Quantity - 1;
        this.SalesOrder2[0].Data[0].quantity =
          this.SalesOrder2[0].Data[0].quantity + 1;
      }
    },
    // 配送地址的数量 增加
    addGoods(index, item) {
      //分配
      if (item.isSettle) {
        if (item.Quantity == this.SalesOrder2[0].Data[0].quantity - 1) {
          // 数量时动态变化的
          uni.showToast({
            title: "商品数量已达上限",
            icon: "error",
          });
          return;
        }
        if (item.Quantity < this.SalesOrder2[0].Data[0].quantity) {
          item.Quantity = item.Quantity + 1;
          this.SalesOrder2[0].Data[0].quantity =
            this.SalesOrder2[0].Data[0].quantity - 1;
        } else {
          uni.showToast({
            title: "商品数量已达上限",
            icon: "error",
          });
        }
      } else {
        uni.showToast({
          title: "请先勾选地址!",
          icon: "error",
        });
      }
    },
    radioChange(index, item) {
      //判断所选地址
      this.addressList[index].isSettle = !this.addressList[index].isSettle;
      // if (!this.addressList[index].isSettle) {
      //   this.addressList[index].Quantity = 1;
      // }
    },
    async addressListMethods() {
      //获取地址列表
      const res = await getAddressList(this.addressForm);
      this.addressList = res.tableData;
      this.addressList.forEach((item) => {
        item.isSettle = false;
        item.Quantity = 0;
      });
      this.addressList = this.addressList.filter((item) => {
        return (
          item.Address_SerialNumber !==
          uni.getStorageSync("AddressData").Address_SerialNumber
        );
      });
    },
    //支持选择多个收货地址
    Select_multiple_harvest_addresses(type) {
      this.type = type;
      // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
      this.$refs.popup.open(type);
    },
    fixed() {
      //底部模块高度获取
      uni
        .createSelectorQuery()
        .select("#fixed")
        .boundingClientRect((res) => {
          this.fixedHeight = res.height + this.rpxToPx(20);
        })
        .exec();
    },
    handlecount(i) {
      this.count = i;
      if (uni.getStorageSync("AddressData")) {
        if (i == 0) {
          this.sales_order.Sales_Address = this.Address.Address.replace(
            " ",
            "/"
          )
            .replace(" ", "/")
            .replace(" ", "/");
          this.sales_order.Delivery_Amount = this.DeliveryAmount;
        } else {
          this.sales_order.Sales_Address = "用户自提";
          this.sales_order.Delivery_Amount = 0;
        }
      }
    },
    Getdistance(Store_SerialNumber) {
      uni.request({
        //查询所选地址与发货点的距离
        header: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
        url: app.globalData.Domain_Name + "/WeChatAddressDistance", //销售价格单
        method: "POST",
        data: {
          latitude: this.Address.latitude,
          longitude: this.Address.longitude,
          Store_SerialNumber,
          Open_ID: app.globalData.openid,
        },
        success: ({ data }) => {
          if (data.Data.length == 0 && data.EXIST) {
            uni.showToast({
              title: "该地址无法进行配送服务,请更换地址",
              icon: "none",
            });
            this.DeliveryAmount = 0;
            this.Sales_Amount = 0;
            this.distance = "";
            this.ispay = false;
          } else if (data.Data.length == 1 && data.EXIST) {
            this.ispay = true;
            this.DeliveryAmount = data.Data[0].Delivery_Amount;
            this.Sales_Amount = data.Data[0].Sales_Amount;
            this.distance = Number(data.Data[0].distance).toFixed(2);
            this.sales_order.Delivery_Amount = this.DeliveryAmount;
          }
        },
      });
    },
    agree() {
      //协议确认
      this.mask = false;
      uni.setStorageSync("mask", true);
      app.globalData.Rights_Type = "1";
    },
    time() {
      let year = new Date().getFullYear();
      let month = new Date().getMonth() + 1;
      let days = new Date().getDate();
      let hour = new Date().getHours();
      let minutes = new Date().getMinutes();
      let second = new Date().getSeconds();
      if (month < 10) {
        month = "0" + month;
      }
      if (days < 10) {
        days = "0" + days;
      }
      if (hour < 10) {
        hour = "0" + hour;
      }
      if (minutes < 10) {
        minutes = "0" + minutes;
      }
      if (second < 10) {
        second = "0" + second;
      }
      this.times =
        year +
        "-" +
        month +
        "-" +
        days +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        second;
    },
    submit() {
      //调起支付方式
      if (this.Address != null) {
        if (this.payway) {
          this.isShow2 = true;
          this.sales_orders.forEach((item, index) => {
            item.Sales_Message = this.SalesOrder[index].message;
            item.Delivery_Amount = this.count ? 0 : this.DeliveryAmount;
          });
        } else {
          this.isShow = true;
          this.sales_order.Sales_Message = this.SalesOrder[0].message;
        }
      } else {
        uni.showToast({
          title: "请选择地址",
          icon: "error",
        });
      }
    },
    handleClose() {
      //关闭支付关闭
      if (this.payway) {
        this.isShow2 = false;
      } else {
        this.isShow = false;
      }
    },
    tags() {
      uni.showModal({
        title: "系统提示",
        content:
          "根据您选择送货的地址不同,配送费可能会发生变化(点击我已知晓后续将不再提示该提示)",
        confirmText: "我已知晓",
        success(res) {
          if (res.confirm) {
            uni.setStorageSync("tags", "1");
            uni.navigateTo({
              url: "/pages/my/address?Path=/pages/index/submitOrder",
            });
          }
        },
      });
    },
    onAddress(index) {
      this.Address_index = index ? index : 0;
      //跳转到地址列表
      if (uni.getStorageSync("tags") == "" ? true : false) {
        this.tags();
      } else {
        uni.navigateTo({
          url: "/pages/my/address?Path=/pages/index/submitOrder",
        });
      }
    },
    MultipleAddresses(item) {
      this.dataII = item;
      // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
      this.$refs.popupNumber.open("bottom");
    },
    rpxToPx(rpx) {
      //rpx转px
      const screenWidth = uni.getSystemInfoSync().screenWidth;
      return (screenWidth * Number.parseInt(rpx)) / 750;
    },
    accAdd(arg1, arg2) {
      //浮点型相加
      var r1, r2, m;
      try {
        r1 = arg1.toString().split(".")[1].length;
      } catch (e) {
        r1 = 0;
      }
      try {
        r2 = arg2.toString().split(".")[1].length;
      } catch (e) {
        r2 = 0;
      }
      m = Math.pow(10, Math.max(r1, r2));
      return (arg1 * m + arg2 * m) / m;
    },
    async querData() {
      const Key = { Key: "B_classify_test1" };
      const res = await submitODPquery(Key);
    },
  },
};
</script>

<style lang="scss">
page {
  background-color: #f8f9fa;
}
.mask {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;

  .model_box {
    width: 80%;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    // z-index: 1000;
    background: #fff;
    // height:48%;
    border-radius: 15rpx;
  }

  .mb-content {
    padding: 10rpx 20rpx 10rpx 25rpx;
    box-sizing: border-box;
    height: 80%;
    overflow: scroll;
  }

  .mb-tit {
    padding: 15rpx 0rpx;
    box-sizing: border-box;
    font-size: 34rpx;
    text-align: center;
  }

  .mb-con {
    font-size: 30rpx;
    text-indent: 2rem;
    line-height: 1.5;
  }

  .mb-con1 {
    font-size: 30rpx;
    text-indent: 2rem;
    display: flex;

    .mb-a {
      // width: 180rpx;
      height: 40rpx;
      display: inline-block;
      padding: 0;
      margin: 0;
      color: #006df7;
      text-decoration: underline;
      text-indent: 0rem;
    }
  }

  .checkbox {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 11%;
  }

  .checkbox .qx {
    width: 50%;
    text-align: center;
    border-right: 1rpx solid #efefef;
  }

  .qr {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    box-szing: border-box;
    font-size: 30rpx;
    padding: 0;
    padding-right: 30rpx;

    .noUse {
      width: 50%;
      text-align: center;
      border-right: 1rpx solid #f3f3f3;
      color: #bbbbbb;
      padding-bottom: 15rpx;
    }

    .agree {
      width: 50%;
      text-align: center;
      font-size: 30rpx;
      color: #006df7;
      padding-bottom: 15rpx;
    }
  }
}
/deep/ .uni-popup__wrapper {
  padding: 20rpx;
  box-sizing: border-box;
  height: 332px;
  overflow: auto;
}
</style>